package org.martyn.danbodroid;

import org.martyn.danbodroid.database.DatabaseHelper;
import org.martyn.danbodroid.database.ServersTable;
import org.martyn.danbodroid.preferences.Preferences;
import org.martyn.danbooru.Danbooru;
import org.martyn.danbooru.DanbooruConnectSettings;

import android.app.Application;
import android.app.backup.SharedPreferencesBackupHelper;
import android.content.SharedPreferences;

public class DanboDroid extends Application
{
	private DatabaseHelper databaseHelper;
	private Danbooru danbooru;
	
	@Override
	public void onCreate()
	{
		databaseHelper = new DatabaseHelper(this.getApplicationContext());
		
		setupDefaultDanbooru();
		
	}

	private void setupDefaultDanbooru()
	{
		if(!danbooruIsSet())
		{
			int selectedServer = Preferences.loadSelectedServerSettings(getApplicationContext());
			
			if(selectedServer != -1)
			{
				danbooru = new Danbooru(ServersTable.get(databaseHelper, selectedServer));
			}
		}
	}

	public boolean danbooruIsSet()
	{
		return (danbooru == null) ? false : true;
	}

	public DatabaseHelper getDatabaseHelper()
	{
		return databaseHelper;
	}

	public Danbooru getDanbooru()
	{
		return danbooru;
	}
	
	public void setDanbooru(Danbooru danbooru)
	{
		this.danbooru = danbooru;
	}

}
